package com.qc.ayouth.shop.core.config.serializer;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializeWriter;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Date;

public class DateSerializer implements ObjectSerializer {

    public static final DateSerializer instance = new DateSerializer();
//    private static final String defaultPattern = "yyyy-MM-dd HH:mm:ss";

    public DateSerializer() {
    }

    @Override
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;
        if (object == null) {
            out.writeNull();
        } else {
            Date date = (Date) object;
            out.writeLong(date.getTime());
//            out.writeString(result.format(DateTimeFormatter.ofPattern(defaultPattern)));
        }
    }

}
